package cn.ekuma.epos.datalogic.define.dao.erp;

import java.util.List;

import com.openbravo.bean.erp.viewbean.LotNoStockCurrentInfo;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.query.QBFParameters;
import com.openbravo.data.loader.serialize.DataRead;
import com.openbravo.data.loader.serialize.Datas;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.sqlbuilder.QBFBuilder;
import com.openbravo.data.loader.serialize.serializer.write.SerializerWriteBasic;
import com.openbravo.data.loader.sentence.StaticSentence;

import e.odbo.data.dao.ViewDAO;

public class ProductLotNoStoreInfoDAO extends ViewDAO<LotNoStockCurrentInfo> {

	private static String LIST_Sql="SELECT P.ID, P.REFERENCE, P.CODE, P.NAME, P.PRICEBUY, P.PRICESELL, L.NAME ,A.DESCRIPTION,C.LOTNO,C.UNITS,C.VALIDITYDATE,C.CREATEDATE "
        + "FROM LOTNO_STOCKCURRENT C LEFT OUTER JOIN ATTRIBUTESETINSTANCE A ON  C.ATTRIBUTESETINSTANCE_ID=A.ID ,PRODUCTS P ,LOCATIONS L  ";

	
	public ProductLotNoStoreInfoDAO(I_Session s) {
		super(s);
	}

	@Override
	public LotNoStockCurrentInfo readValues(DataRead dr,LotNoStockCurrentInfo obj) throws BasicException {
		if(obj==null)
			obj=new LotNoStockCurrentInfo();
		obj.setM_ID(dr.getString(1));
		obj.setM_sRef(dr.getString(2));
		obj.setM_sCode(dr.getString(3));
		obj.setM_sName(dr.getString(4));
		obj.setM_dPriceBuy(dr.getDouble(5));
		obj.setM_dPriceSell(dr.getDouble(6));
		obj.setM_Location(dr.getString(7));
		obj.setAttrsetInsDesc(dr.getString(8));
		obj.setLotNo(dr.getString(9));
		obj.setM_unit(dr.getDouble(10));
		obj.setValidityDate(dr.getTimestamp(11));
		obj.setCreateDate(dr.getTimestamp(12));
		return obj;
	}

	@Override
	public Class getSuportClass() {
		return LotNoStockCurrentInfo.class;
	}
	

	    public List<LotNoStockCurrentInfo> list(Object filter) throws BasicException {
	        return new StaticSentence(s,new QBFBuilder( LIST_Sql+ "WHERE C.PRODUCT=P.ID AND C.LOCATION=L.ID AND ?(QBF_FILTER)",new String[]{"P.ID", "C.UNITS"}), new SerializerWriteBasic(new Datas[]{Datas.OBJECT, Datas.STRING,Datas.OBJECT, Datas.DOUBLE}), this).list(filter);
	    }

	@Override
	public List<LotNoStockCurrentInfo> query(QBFParameters qbfParameters) throws BasicException {
		return new StaticSentence(s,new QBFBuilder( LIST_Sql+ "WHERE C.PRODUCT=P.ID AND C.LOCATION=L.ID AND ?(QBF_FILTER)"), null, this).list(qbfParameters);

	}
}
